import React from 'react';

class ParentCom extends React.Component {

  state = {
    name: ''
  }

  changePropsName = (name) => {
    this.setState({ name })
  }
  render() {
    return (

      <div>
        <h1>我是父元素节点</h1>
        <ChildCom changeName={this.changePropsName} name={this.state.name} />
      </div>

    )
  }

}

class ChildCom extends React.Component {

  render() {
    return (
      <div>
        <h2>我是子元素的节点</h2>
        <p>名字:{this.props.name}</p>
        <button onClick={this.changeName}>修改名字</button>
      </div>
    )
  }
  changeName = () => {
    this.props.changeName('李四')
  }
}


export default ParentCom